<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			img{
				display: inline-block;
				height: 400px;
				width: 400px;
				position: relative;
				overflow: hidden;
				color: transparent;
			}
			img:before{
				content: '';
				position: absolute;
				width: 100%;
				height: 100%;
				background-color: #f0f3f9;
				visibility: visible;
			}
			img:after{
				content: attr(alt);
				position: absolute;
				bottom: 0;
				left: 0;
				width: 100%;
				font: 14px/30px "microsoft yahei";
				text-align: center;
				background-color: rgba(0,0,0,.5);
				color: #fff;
				transform: translateY(100%);
				transition: transform .25s;
				overflow: hidden;
				visibility: visible;
			}
			img:hover:after{
				transform: translateY(0);
			}
		</style>
	</head>
	<body>
		<img  alt="帅哥冥想图" >
		<button type="button" onclick="getSrc()">添加图片</button>
		<script type="text/javascript">
			//不兼容edge
			function getSrc(){
				document.querySelector("img").setAttribute("src","../img/1.jpg");
			}
		</script>
	</body>
</html>
